﻿//===================================================================================
// Copyright (c) Ryan Garrett.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================

using System;
using Caffeine.Core.Test.TestModel.PropertyRegistrations;
using Caffeine.Core.Test.TestModel.ValidationModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Caffeine.Core.Test
{
    [TestClass]
    public class ModelPropertyValidationTester
    {
        [TestMethod]
        public void ModelNoPropertiesValidationTest()
        {
            Creator.Create<ModelWithNoProperties>();
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void DuplicatePropertyValidationTest()
        {
            Creator.Create<DuplicatePropertyRegistrationModel>();
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void ShadowedPropertyValidationTest()
        {
            Creator.Create<ShadowedPropertyModel>();
        }

        [TestMethod]
        public void InternalPropertyValidationTest()
        {
            Creator.Create<InternalPropertyModel>();
        }

        [TestMethod]
        public void PrivatePropertyValidationTest()
        {
            Creator.Create<PrivatePropertyModel>();
        }

        [TestMethod]
        public void ProtectedPropertyValidationTest()
        {
            Creator.Create<ProtectedPropertyModel>();
        }

        [TestMethod]
        public void ProtectedInternalPropertyValidationTest()
        {
            Creator.Create<ProtectedPropertyModel>();
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void NullPropertyValidationTest()
        {
            Creator.Create<ReturnNullModel>();
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void WrongInstancePropertyValidationTest()
        {
            Creator.Create<WrongInstanceModel>();
        }

        [TestMethod]
        public void FactoryDoesNotValidateTest()
        {
            IModelFactory factory = new ModelFactory();
            factory.ValidateModelProperties = false;
            factory.CreateModel<WrongInstanceModel>();
        }
    }
}
